<!-- 组件列表 -->
<template>
  <div class="app-container">
    <el-button type="primary" icon="el-icon-plus" circle @click="$api.go('/design/module-detail')" />
    <el-button icon="el-icon-search" circle @click="initList()" />
    <el-table :data="list" row-key="id" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="#" width="65">
        <template slot-scope="scope">
          <span>{{ scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="组件名称" width="260">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="组件变量" width="260">
        <template slot-scope="scope">
          <span>{{ scope.row.variable }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="组件介绍" width="360">
        <template slot-scope="scope">
          <span>{{ scope.row.descs }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="150">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" circle @click="handleUpdate(scope.row)" />
          <el-button size="mini" type="danger" icon="el-icon-delete" circle @click="handleDelete(scope.row)" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="组件图片" width="360">
        <template slot-scope="scope">
          <el-tooltip v-if="scope.row.thumb" placement="top">
            <div slot="content">
              <img class="tooltip-img" :src="scope.row.thumb" height="500">
            </div>
            <img v-if="scope.row.thumb" :src="scope.row.thumb" height="60">
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-if="page.total!=0" :total="page.total" :page.sync="page.page" :limit.sync="page.size" @pagination="initList" />
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data () {
    return {
      loading: false,
      list: [],
      page: { page: 1, size: 20, total: 0 }
    }
  },
  created () {
    this.initList()
  },
  mounted () { },
  methods: {
    initList () {
      this.$api.get('/api/design/module', this.page)
        .then(response => {
          this.list = response.data
          this.page.total = response.total
        })
    },
    handleUpdate (data) {
      this.$api.go('/design/module-detail',{id:data.id})
    },
    handleDelete (data) {
      this.$api.deleteConfirm('/api/design/module', { id: data.id }).then(res => {
        this.initList()
      })
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
